package sukzessiv;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;


public class TCReader {

	String caseName;
	int alpha, beta;
	public int epsilon;
	ArrayList<Kunden> kunden;
	
	int[] providerEinkauf;

	public TCReader(String dateiName){
		
	  try{
		  
		int enumerator;
		kunden = new ArrayList<Kunden>();
		
		BufferedReader einlesen = new BufferedReader(new FileReader("TestCases\\" + dateiName + ".txt"));
		String puffer = new String();
		
		for (int i=1; i<=7; i++){
			puffer = einlesen.readLine();
			switch (i) {
			case 2:
				caseName = puffer;
				break;
			case 4:
				enumerator = 0;
				
				while(enumerator < puffer.length()){
					if (puffer.charAt(enumerator) != ' '){
						enumerator += 2;
						int count = 0;
						while (puffer.charAt(enumerator) != ' '){
							count++;
							enumerator++;
						};
						if (alpha == 0){
							alpha = Integer.parseInt(puffer.substring(enumerator-count, enumerator));
						}else if(epsilon == 0){
							epsilon = Integer.parseInt(puffer.substring(enumerator-count, enumerator));
						}else if(beta == 0){
							beta = Integer.parseInt(puffer.substring(enumerator-count, enumerator));
						}
					}
					enumerator++;
				}
			default:
				break;
			}
		}
		
		while(!puffer.contains("Gesamt")){
			
			puffer=einlesen.readLine();
			
			if(puffer.charAt(0) == 'K'){
				
				int countA = -1;
				int[][] k = new int[100][10];
				ArrayList<ArrayList<Integer>> abhaengigkeiten = new ArrayList<ArrayList<Integer>>();
					
				while(puffer.length() != 0){
					boolean check = true;
					int arrayPos = 0;
					countA++;
					puffer = einlesen.readLine();
					
					enumerator = 0;
					while(enumerator < puffer.length()){
						if (puffer.charAt(enumerator) != ' '){
							int count = 0;
							while (puffer.charAt(enumerator) != ' '){
								count++;
								enumerator++;
							}
							String substring = puffer.substring(enumerator-count, enumerator);
							
							if(arrayPos != 1 | check != true){
								k[countA][arrayPos] = Integer.parseInt(substring);
								arrayPos++;
							}else{
								check = false;
								if (substring.charAt(0) != '-'){
									ArrayList<Integer> a = new ArrayList<Integer>();
									a.add(countA+1);
									int enum2 = 0;
									int enum2Count = 0;
									while(enum2 < substring.length()){
										enum2Count = 0;
										while (substring.charAt(enum2) != ','){
											enum2++;
											enum2Count++;
										}
										a.add(Integer.valueOf(substring.substring(enum2-enum2Count, enum2)));
										enum2++;
									}
									
									abhaengigkeiten.add(a);
								}
							}
						}
						enumerator++;
						
					}
				}
				int[][] copy = new int[countA][10];
				
				for(int i = 0; i < countA ; i++){
					for(int j = 0; j < 10;j++){
						copy[i][j] = k[i][j];
					}
				}
				
				kunden.add(new Kunden(copy, abhaengigkeiten));
			}
			
			
		}
		
		puffer = einlesen.readLine();
		enumerator = 0;
		int countZ = 0;
		int[] speicher = new int[1000];
		
		while(enumerator < puffer.length()-1){
			if(puffer.charAt(enumerator) == '|'){
				countZ++;
				int count = 0;
				enumerator++;
				while (puffer.charAt(enumerator) != '|'){
					count++;
					enumerator++;
				}
				speicher[countZ-1] = Integer.parseInt(puffer.substring(enumerator-count, enumerator));
				
			}else{
				enumerator++;
			}
		}
		int[] copy = new int[countZ];
		
		for(int i = 0; i < countZ ; i++){
				copy[i] = speicher[i];
		}
		providerEinkauf = speicher;
		
	  }catch(Exception e){
		  System.out.println("Fehler beim Einlesen");
	  }
	
	

	
	
	}
	
	public int uebergebeE0(){
		return epsilon;
	}
	
	public int uebergebeBeta(){
		return beta;
	}
	
	public int uebergebeAlpha(){
		return alpha;
	}
	
	}




